<?php
/**
* 发票
*
* @author chenping<chenping@shopex.cn>
* @version $Id: tax.php 2013-3-12 17:23Z
*/
class erpapi_shop_response_components_order_tax extends erpapi_shop_response_components_order_abstract
{
    const _APP_NAME = 'ome';

    public function convert()
    {
        $this->_platform->_newOrder['is_tax']           = ($this->_platform->_ordersdf['is_tax'] === 'true' || $this->_platform->_ordersdf['is_tax'] === true  || $this->_platform->_ordersdf['is_tax'] === '1') ? 'true' : 'false';
        $this->_platform->_newOrder['cost_tax']         = (float)$this->_platform->_ordersdf['cost_tax'];
        $this->_platform->_newOrder['tax_no']           = $this->_platform->_ordersdf['tax_no'];
        $this->_platform->_newOrder['tax_title']        = $this->_platform->_ordersdf['tax_title'];
        $shop_id = $this->_platform->__channelObj->channel['shop_id'];
        $taxconf = app::get('ome')->getConf('shop.tax.config.'.$shop_id);

        //前端店铺下tab发票配置页 前端店铺下单发票设置
        if($this->_platform->_newOrder['is_tax'] == 'false' && $taxconf['config'] == '1'){
            $this->_platform->_newOrder['is_tax'] = 'true';
            $this->_platform->_newOrder['tax_title'] = $taxconf['title'];
        }
        
        //需要开票的并且是要电子发票的
        if($this->_platform->_newOrder['is_tax'] == "true" && intval($this->_platform->_ordersdf["invoice_kind"]) == 1){
            $this->_platform->_newOrder["invoice_mode"] = "1";
        }
    }
    
    public function update()
    {
        if ($this->_platform->_ordersdf['tax_title'] && $this->_platform->_ordersdf['tax_title'] != $this->_platform->_tgOrder['tax_title']) {
            $this->_platform->_newOrder['tax_title'] = $this->_platform->_ordersdf['tax_title'];
        }
        
        $this->_platform->_ordersdf['is_tax'] = ($this->_platform->_ordersdf['is_tax'] === 'true' || $this->_platform->_ordersdf['is_tax'] === true) ? 'true' : 'false';

        if ($this->_platform->_ordersdf['is_tax'] != $this->_platform->_tgOrder['is_tax']) {
            $this->_platform->_newOrder['is_tax'] = $this->_platform->_ordersdf['is_tax'];
        }

        if ($this->_platform->_ordersdf['tax_no'] && $this->_platform->_ordersdf['tax_no'] != $this->_platform->_tgOrder['tax_no']) {
            $this->_platform->_newOrder['tax_no'] = $this->_platform->_ordersdf['tax_no'];
        }
    }
}